package com.wisemoresystem.seal.action.useapply.verify;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.model.t_seal_use_apply;
import com.wisemoresystem.seal.model.t_seal_use_apply_verify;
import com.wisemoresystem.seal.model.t_user;
import com.wisemoresystem.seal.service.MacService;
import com.wisemoresystem.seal.service.UseApplyService;
import com.wisemoresystem.seal.service.WkflowService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 申请审批
 * 
 * @author Administrator
 *
 */
@Controller("ixSealUseApplyVerifyAction")
@Scope("prototype")
@RequestMapping("/ix/useapply/apply/verify")
public class SealUseApplyVerifyAction extends ProjBaseAction {

	@Autowired
	private WkflowService wkService;
	@Autowired
	private UseApplyService uAService;
	@Autowired
	private MacService mService;

	/**
	 * 使用申请列表
	 * 
	 * @param srh_reason
	 *            用印事由
	 * @param srh_user
	 *            申请人
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list() {
		List<Map<String, Object>> list = uAService
				.selectUnVerifyApplyList(page);

		ModelAndView mv = new ModelAndView("/jsp/useapply/verify/list");
		mv.addObject("list", list);
		return mv;
	}

	@RequestMapping("/detail")
	public ModelAndView detail(String verify_id) {

		t_seal_use_apply_verify verify = oc.findObjById(verify_id,
				t_seal_use_apply_verify.class);

		t_seal_use_apply apply = oc.findObjById(verify.getApply_id(),
				t_seal_use_apply.class);
		t_user user = oc.findObjById(apply.getApply_user(), t_user.class);

		List<Map<String, Object>> macList = mService.selectMac(WebTools
				.getCurrentBankId());
		List<Map<String, Object>> sealList = uAService.selectSeal(WebTools
				.getCurrentBankId());
		Map<String, Object> files = uAService.getMapFiles(apply);

		List<Map<String, Object>> verifyList = uAService.selectVerifyList(apply
				.get_id());

		ModelAndView mv = new ModelAndView("/jsp/useapply/verify/detail");
		mv.addObject("verify", verify);
		mv.addObject("macList", macList);
		mv.addObject("sealList", sealList);
		mv.addObject("apply", apply);
		mv.addObject("user", user);
		mv.addObject("files", files);
		mv.addObject("verifyList", verifyList);
		return mv;
	}

	@RequestMapping("/verify")
	public ModelAndView verify(String verify_id, String verify,
			String president_opinion) {

		wkService.verify(verify_id, verify, president_opinion);

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}

}